﻿<phone:PhoneApplicationPage
    x:Class="Omnia.Wallet.Views.LanguageDownloadView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Converters="clr-namespace:Omnia.Converters;assembly=Omnia.Converters"
    xmlns:viewmodel="clr-namespace:Omnia.ViewModels;assembly=Omnia.ViewModels"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="False" d:DesignHeight="800" d:DesignWidth="480">

    <phone:PhoneApplicationPage.Resources>
        <Converters:EnumTranslateConverter x:Key="EnumTranslateConverter"/>
        <Converters:CultureNameToNativeNameConverter x:Key="CultureNameToNativeNameConverter"/>
    </phone:PhoneApplicationPage.Resources>
    
    <Grid x:Name="LayoutRoot">
        <Grid.DataContext>
            <viewmodel:LanguageDownloadViewModel/>
        </Grid.DataContext>
        <controls:Pivot Title="{StaticResource IDS_PAGE_TITLE}">
            <controls:PivotItem Header="{StaticResource IDS_ITEM_HEADER_DOWNLOADLANGUAGE}">
                <Grid>
                    <Grid Visibility="{Binding ListVisibility, Mode=OneWay}">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <ListBox ItemsSource="{Binding FetchedLanguages}" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ListBoxItem">
                                                <RadioButton IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Content="{Binding Converter={StaticResource CultureNameToNativeNameConverter}}"/>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                        </ListBox>

                        <ProgressBar IsIndeterminate="True" Visibility="{Binding BusyIndicatorVisibility}"/>

                        <Button Grid.Row="1" Content="{StaticResource IDS_LABEL_LANGUAGE_DOWNLOAD_START}" Command="{Binding DownloadCommand, Mode=OneWay}"/>
                    </Grid>
                    <Grid Visibility="{Binding DownloadPanelVisibility, Mode=OneWay}">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <StackPanel>
                            <TextBlock Text="{Binding SelectedLanguage, Converter={StaticResource CultureNameToNativeNameConverter}}"/>
                            <TextBlock>
                                <Run Text="{StaticResource IDS_LABEL_LANGUAGE_DOWNLOAD_DOWNLOADED}" />
                                <Run Text="{Binding DownloadedBytes}"/>
                                <Run Text="/"/>
                                <Run Text="{Binding TotalBytes}"/>
                                <Run Text="("/>
                                <Run Text="{Binding DownloadedPercent}"/>
                                <Run Text=")"/>
                            </TextBlock>
                            <ProgressBar Margin="0,12" Value="{Binding Path=DownloadedPercent}" />
                        </StackPanel>
                        <Button Grid.Row="1" Content="{StaticResource IDS_LABEL_LANGUAGE_DOWNLOAD_CANCLE}"/>
                    </Grid>
                </Grid>
            </controls:PivotItem>
            <controls:PivotItem Header="{StaticResource IDS_ITEM_HEADER_DONE}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>
                    <ListBox ItemsSource="{Binding ExistsLanguageFile}" 
                             SelectedItem="{Binding SelectedExistLanguage, Mode=TwoWay}" >
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <RadioButton IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" 
                                                         Content="{Binding Converter={StaticResource CultureNameToNativeNameConverter}}"/>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                    </ListBox>
                    
                    <Grid Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>

                        <Button Content="{StaticResource IDS_LABEL_LANGUAGE_SETTOUSE}" Command="{Binding SetLanguageCommand, Mode=OneWay}"/>
                        <Button Content="{StaticResource IDS_LABEL_LANGUAGE_DELETE}" Grid.Column="1" Command="{Binding Path=DeleteCommand}" />
                    </Grid>
                </Grid>
            </controls:PivotItem>
        </controls:Pivot>
        <Grid.Background>
            <ImageBrush ImageSource="{Binding BackgroundImageSource, Mode=OneWay}" Stretch="{Binding GlobalSettings.BackgroundImageStretch}" />
        </Grid.Background>
    </Grid>

</phone:PhoneApplicationPage>